<?php
// REICH - 14.07.2010
// File for logic of global search functionallity
$db = new WebSalesDB();
$searchstring = DB::cleanQuery($_POST['searchstring']);
$query = "SELECT * FROM CostBiterStock WHERE MATCH(ShortDesc,Manufacturer,MasterCat,WebDesc,WebCat,SubCat) AGAINST('$searchstring') OR UCASE(Manufacturer) LIKE UCASE('%$searchstring%')";
$result = DB::query($query);

$count = DB::getCount($result);
?>
<div id="searchtopcontainer">
    <div id="searchtopinnercontainer">
        <div id="searchtopinnercontainer2">
            <div id="searchtopitemcount">
                <b>Wir haben <?php echo $count; ?> Artikel für Sie!</b>
            </div>
        </div>
    </div>
</div>
<div style="float: left; display: block; width: 100%; clear: both; height: 10px;">&nbsp;</div>
<div id="search" style="opacity:1;"> <?php
    while ($row = DB::fetch($result)) { ?>
    <div class="product">
        <div class="productimg">
            <a href="/moreinfo/<?php echo $row['StockCode'] ?>/<?php echo $CleanCode->Encode($row[MasterCat]) ?>/">
                    <?php $ImageChecker->showImg("/web3g/img/accessories/" . $row['StockCode'] . ".jpg", "146", "106", $row['WebDesc'], "", ""); ?>
            </a>
        </div>
        <div class="productDesc">
                <?php
                //truncate title
                $title_limit = 55;
                if (strlen($row['WebDesc']) > $title_limit) {
                    $current_title = substr($row['WebDesc'], 0, strpos($row['WebDesc'], " ", 60)) . "...";
                } else {
                    $current_title = $row['WebDesc'];
                }
                $current_title = utf8_encode($current_title);

                //truncate info
                $prod_info = explode("****", $row['ExtendedDesc']);
                $info_limit = 195;
                if (strlen($prod_info[0]) > $info_limit) {
                    $current_info = substr($prod_info[0], 0, strpos($prod_info[0], " ", 200)) . "...";
                } else {
                    $current_info = $prod_info[0];
                }
                $current_info = utf8_encode($current_info);
                ?>
            <a href="/moreinfo/<?php echo $row['StockCode'] ?>/<?php echo $CleanCode->Encode($row[MasterCat]) ?>/"><h3><?php echo $current_title; ?></h3></a><br />
            <div><?php echo $current_info; ?></div>
        </div>
        <div class="productPrice">
            <img src="/images/spacer.gif" width="100%" height="15" />
                <?php /* ?><span class="rrp"><?php if($pd['RRP'] > 0){ ?>Was &pound;<?php echo number_format($pd['RRP'])?><?php } ?></span><?php */ ?>
            <br /><span class="price">&euro;<?php echo number_format($row['WebRPHIGH'], 2); ?></span>
                <?php /* ?><br /><span class="saving"><?php if($pd['RRP'] > 0){ ?>Save <?php echo $pd['Saving']?><? } ?></span><?php */ ?>
            <img src="/images/spacer.gif" width="100%" height="10" />
            <img src="/images/item/item_hline_01.jpg" />
            <img class="productSpacerLast" src="/images/spacer.gif" width="100%" height="10" />
            <a href="/moreinfo/<?php echo $row['StockCode'] ?>/<?php echo $CleanCode->Encode($row[MasterCat]) ?>/">
                <img src="/images/spacer.gif" class="spritebg infoBtn" />
            </a>
            <form action="/basket/" method="post" style="display:inline-block;">
                <input type="hidden" name="esid" value="<?php echo $_SESSION['esid']; ?>" />
                <input type="hidden" name="acid" value="<?php echo $row['StockCode'] ?>" />
                <input type="image" src="/images/spacer.gif" class="spritebg buyBtn" />
            </form>
        </div>
    </div>
    <img class="productBottomShadow" src="/images/item/item_btmshad.gif" width="763" height="5" style="float:left;" />
    <div style="height:10px; width:100%; display:block; float:left; clear:both;">&nbsp;</div>
        <?php
    }
    ?>
</div>
<div style="float:left; display:block; width:100%; clear:both; height:10px;">&nbsp;</div>